package com.cn.sl.server.api.system.file.model.dto

import com.cn.sl.server.api.system.file.config.LocalFileUploadConfig
import com.cn.sl.server.api.system.file.model.entity.SysFileEntity
import com.cn.sl.server.api.system.file.model.enumerate.FileType
import io.swagger.v3.oas.annotations.media.Schema
import org.dromara.hutool.extra.spring.SpringUtil

@Schema(description = "文件信息")
data class SysFileDto(
    @field:Schema(description = "文件id")
    val id: Long,
    @field:Schema(description = "文件名称")
    val fileName: String,
    @field:Schema(description = "文件类型")
    val type: FileType,
    @field:Schema(description = "文件路径")
    val url: String,
) {
    constructor(entity: SysFileEntity) : this(
        entity.id,
        entity.fileName,
        entity.type,
        entity.url
    )

    val fullUrl: String
        get() {
            val config = SpringUtil.getBean(LocalFileUploadConfig::class.java)
            return "${config.fullUrlPrefix}${url}"
        }
}